package p2perror

import (
	"errors"
	"fmt"
	"sync"

	"hundsun.com/hsl/hschain/common/log/logging"
)

var logger logging.Log
var once sync.Once

//Init 初始化
func Init(log logging.Log) {
	once.Do(func() {
		logger = log
	})
}

//ErrNotFound 对象找不到
var ErrNotFound = errors.New("item not found")

//ErrWrongType 通用错误
var ErrWrongType = errors.New("type miss match")

//Log ...
func Log() logging.Log {
	return logger
}

//Errorf 打印并返回错误日志
func Errorf(format string, a ...interface{}) error {
	err := fmt.Errorf(format, a...)
	logger.Error(err)
	return err
}
